home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / baswiz17.zip / S&B4EGA.BAS < prev    next >
BASIC Source File  |  1991-04-01  |  8KB  |  188 lines

  1. ' =======================================================
  2. '  S&B4EGA.BAS  Copyright (c) 1990  Michael Welch
  3. '  included with BasWiz by permission
  4. ' =======================================================
  5. '  Name:  S&B4EGA.BAS - Sticks and Boxes for EGA
  6. '  Type:  Main Module
  7. '  Lang:  Microsoft QuickBASIC v4.5
  8. '  Ver:   1.10
  9. '  Date:  10/15/1990
  10. '  By:    Michael Welch of Dallas, Texas
  11. '  Reqs:  Crescent Software's PDQ.LIB
  12. '         Tom Hanlin's BASIC Wizard library
  13. '  Purp:  (multifaceted):
  14. '         1.  To demonstrate the efficiency of Crescent's
  15. '             BCOMxx replacement library for QuickBASIC.
  16. '         2.  To demonstrate the capabilities and the
  17. '             extensions of Tom Hanlin's BASIC Wizard
  18. '             library.
  19. '         3.  To demonstrate the color range of the EGA's
  20. '             higher-resolution mode.
  21. '| Mods:  Thomas G. Hanlin III
  22. '|        My modifications were largely a matter of
  23. '|        reformatting the source to appear more like
  24. '|        the other BASWIZ sources, for consistency.
  25. '|        A few other trivial alterations were made.
  26. ' =======================================================
  27.  
  28.    DECLARE FUNCTION PDQRand% (Range%)     ' PDQ replacement for RND
  29.    DECLARE SUB PDQRandomize (Seed%)       ' PDQ replacement for RANDOMIZE
  30.  
  31.    DECLARE SUB GetDisplay (Adapter%, Mono%)
  32.    DECLARE SUB G9Banner (St$, X%, Y%, Xmul%, Ymul%)
  33.    DECLARE SUB G9Box (BYVAL X1%, BYVAL Y1%, BYVAL X2%, BYVAL Y2%, BYVAL Fill%)
  34.    DECLARE SUB G9Cls ()
  35.    DECLARE SUB G9Color (BYVAL Foreground%, BYVAL Background%)
  36.    DECLARE SUB G9Line (BYVAL X1%, BYVAL Y1%, BYVAL X2%, BYVAL Y2%)
  37.    DECLARE SUB G9Locate (BYVAL Row%, BYVAL Column%)
  38.    DECLARE SUB G9Mode (BYVAL Graphics%)
  39.    DECLARE SUB G9Write (St$)
  40.    DECLARE SUB G9WriteLn (St$)
  41.  
  42.    DEFINT A-Z                          ' does not need floating point math
  43.  
  44.    GetDisplay Adapter, Mono            ' check adapter type
  45.    IF Adapter < 4 THEN                 ' just end if less than EGA
  46.       PRINT "Sorry, you need an EGA or VGA for this demo!"
  47.       END
  48.    END IF
  49.  
  50.    DEF SEG = 0
  51.    z = PEEK(&H41C) + (PEEK(&H41D) AND 127) * 256
  52.    PDQRandomize z                      ' RANDOMIZE based on system timer
  53.  
  54.    G9Mode 2                            ' SCREEN 9 replacement
  55.  
  56.    ' Draw a large multi-colored box using
  57.    ' Tom's replacement for the LINE statement
  58.    FOR Y = 1 TO 63
  59.       G9Color Y AND 15, 0              ' implementation of COLOR
  60.       G9Box Y, Y, 639 - Y, 349 - Y, (Y = 100)
  61.    NEXT
  62.  
  63.    ' Next, draw the text in the center
  64.    ' of the box.  This is the intro screen
  65.    ' and isn't really needed for the demo,
  66.    ' though it does demonstrate quick graphics
  67.    ' text printing and the G#Banner extra!
  68.    G9Color 19, 15
  69.    G9Banner "S&B4EGA", 70, 70, 9, 10   ' BASWIZ "extra" (nice!)
  70.    G9Color 5, 0
  71.    G9Locate 12, 11
  72.    G9WriteLn "An EGA-only demo using Tom Hanlin's BASIC Wizard Library"
  73.    G9Locate 13, 11
  74.    G9WriteLn "and Crescent Software's PDQ Library.  Written by Mike Welch."
  75.    G9Color 14, 0
  76.    G9Locate 14, 11
  77.    G9WriteLn "Proudly compiled with Microsoft's QuickBASIC compiler v4.50"
  78.    G9Color 2, 0
  79.    G9Banner "Any Key Continues", 115, 235, 3, 6
  80.  
  81.    DO: LOOP UNTIL LEN(INKEY$)          ' loop until keypress
  82.  
  83.  
  84.    ' The following is the main part of the demo.
  85.    ' In the first loop (where i = 1) we just draw colorful
  86.    ' high-resolution EGA lines in a random order.  PDQ's
  87.    ' more versatile implementation of RANDOMIZE and RND
  88.    ' are used to generate the coordinates and colors of
  89.    ' the lines.  In the second part, we add a sort of
  90.    ' animation feature to the line drawing by erasing
  91.    ' (overwriting a line in black) the third line, or
  92.    ' "tail" if you will.  In the last loop (i = 3), we
  93.    ' just draw a series of fast high-resolution boxes.
  94.    FOR i = 1 TO 3                      ' really, three different demos
  95.       G9Cls                            ' BASWIZ CLS replacement
  96.       G9Locate 25, 32
  97.       G9Write "Any key continues"
  98.       DO                               ' loop until keypress
  99.          z = z + 1                     ' count times looped
  100.          IF z > 1024 THEN              ' if looped 1024 times
  101.             G9Cls                      ' clear the cluttered screen
  102.             G9Locate 25, 32
  103.             G9Write "Any key continues"
  104.             z = 0                      ' reset counter
  105.          END IF
  106.          X2 = PDQRand(639)             ' get random X coordinate
  107.          Y2 = PDQRand(335)             ' get random Y coordinate
  108.          c = PDQRand(15)               ' get random color value
  109.          G9Color c, 0                  ' set color
  110.          IF i = 1 THEN                 ' if this is part 1 of demo
  111.             G9Line X1, Y1, X2, Y2      ' draw a line
  112.          ELSEIF i = 2 THEN             ' if part 2 of demo (animation)
  113.             G9Line X1, Y1, X2, Y2      ' draw a line
  114.             G9Color 0, 0               ' set color to black on black
  115.             G9Line Xo, Yo, X1, Y1      ' erase the tail ("animation")
  116.             G9Color 2, 0               '
  117.             Xo = X1                    ' save old X and Y coordinates
  118.             Yo = Y1                    ' for future "erasure"
  119.          ELSE                          ' part 3 of demo
  120.             G9Box X1, Y1, X2, Y2, 0    ' draw multiple boxes
  121.          END IF
  122.          X1 = X2                       ' save last coordinates such that
  123.          Y1 = Y2                       ' the lines are connected
  124.       LOOP UNTIL LEN(INKEY$)           ' and loop
  125.       z = 0                            ' reset loop counter here
  126.    NEXT
  127.  
  128.    ' Thanks to my friend Earl Montgomery
  129.    ' who gave me the idea for this next
  130.    ' demo.  The addition of this portion
  131.    ' marks v1.10 of S&B4EGA.
  132.    Switch = -1                         ' initialize function switch
  133.    FOR k = 2 TO 4 STEP 2               ' loop twice, increment in DO below
  134.       Yo = 0: Xo = 0                   ' initialize all vars used in loop
  135.       X1 = 0: Y1 = 0
  136.       i = 0
  137.       Switch = Switch + 1              ' incriment function switch
  138.       G9Cls                            ' clear screen
  139.       G9Locate 25, 32
  140.       G9Write "Any key continues"
  141.       DO UNTIL LEN(INKEY$)             ' loop (twice) until keypress
  142.          EndLoop = 0                   ' reset Boolean flag
  143.          DO                            ' derive legal value for animation
  144.             X1 = X1 + Xo               ' add to x-coord
  145.             Y1 = Y1 + Yo               ' add to y-coord
  146.             z = PDQRand(1)             ' used for animation: binary result
  147.             IF X1 < 16 THEN            ' if under x range
  148.                Xo = z * k              ' enlarge value
  149.             ELSEIF X1 > 624 THEN       ' if over x range
  150.                Xo = 0 - z * k - 1      ' decrease value
  151.             ELSEIF Y1 < 16 THEN        ' if under y range
  152.                Yo = z * k              ' enlarge
  153.             ELSEIF Y1 > 315 THEN       ' if over y range
  154.                Yo = 0 - z * k - 1      ' decrease
  155.             ELSE
  156.                EndLoop = -1            ' quit computing and draw box
  157.             END IF
  158.          LOOP UNTIL EndLoop
  159.  
  160.          c = c + 1                     ' increase color counter
  161.          IF c > 63 THEN c = 1          ' reset if out of range
  162.  
  163.  
  164.          i = i + 1                     ' increment loop counter
  165.          G9Color c, 0                  ' set color here
  166.          IF Switch THEN                ' if on SECOND loop
  167.             IF i > 3072 THEN           ' clear screen
  168.                G9Cls
  169.                G9Locate 25, 32
  170.                G9Write "Any key continues"
  171.                i = 0
  172.             END IF
  173.             G9Box X1 - 15, Y1 + 15, X1 + 15, Y1 - 15, c  ' draw filled box
  174.          ELSE
  175.             G9Box X1 - 15, Y1 + 15, X1 + 15, Y1 - 15, 0  ' draw empty box
  176.             IF i > 6144 THEN           ' clear screen
  177.                G9Cls
  178.                G9Locate 25, 32
  179.                G9Write "Any key continues"
  180.                i = 0
  181.             END IF
  182.          END IF
  183.       LOOP
  184.    NEXT
  185.  
  186.    G9Mode 0                            ' restore text mode
  187.    PRINT "";                       ' clears to ANSI screen colors
  188.